package org.example.blog.tools;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.service.MemoryId;
import org.example.blog.service.ArticleService;
import org.example.blog.service.CategoryService;
import org.example.blog.service.MyselfService;
import org.example.blog.vo.ArticleContent;
import org.springframework.stereotype.Component;

import org.example.blog.vo.MyselfInfoVO;

import java.util.List;

@Component
public class Calculatortools {

    private final ArticleService articleService;

    private final CategoryService categoryService;

    private final MyselfService myselfService;

    public Calculatortools(ArticleService articleService, CategoryService categoryService, MyselfService myselfService) {
        this.articleService = articleService;
        this.categoryService = categoryService;
        this.myselfService = myselfService;
    }

    @Tool(name="查找分类下的文章", value="只有用户想查询某个分类的所有文章时，才会执行该工具类，根据参数，查找该分类下有哪些文章，并返回文章名称列表")
    public List<String> findArticle(
            @P(value = "分类名称")String category
    ){
        System.out.println("执行根据分类查找文章工具: " + category);
        return articleService.findAllArticleByCategory(category);
    }

    @Tool(name="查找所有分类", value="只有用户想查询文章分类相关字段时，才会执行该工具类，并查找所有的文章分类")
    public List<String> findCategory(){
        System.out.println("执行查找分类工具");
        return categoryService.findAllCategoryName();
    }

    @Tool(name="查找文章内容", value="只有用户想查询某个文章的内容时，或者某篇文章属于哪个分类、有哪些标签时，才会执行该工具类，根据参数，查找该文章的内容，并返回文章内容。")
    public ArticleContent findArticleContent(
            @P(value = "文章名称")String articleName
    ){
        ArticleContent articleContent = new ArticleContent();

        System.out.println("执行查找文章内容工具: " + articleName);
        String content = articleService.findArticleContent(articleName);
        articleContent.setArticleContent(content);

        System.out.println("执行查找文章标签工具: " + articleName);
        List<String> tag = articleService.findArticleTag(articleName);
        articleContent.setArticleTag(tag);

        System.out.println("执行查找文章分类工具: " + articleName);
        String category = articleService.findArticleCategory(articleName);
        articleContent.setCategory(category);

        return articleContent;
    }




    @Tool(name="查找作者信息", value="只有用户想查询作者信息时，才会执行该工具类，并返回作者信息")
    public MyselfInfoVO findMyselfInfo(){
        System.out.println("执行查找作者信息工具");
        return myselfService.findMyselfInfo();
    }
}
